package cn.medemede.springbootdemo1.service;

import cn.medemede.springbootdemo1.enums.ResultEnum;
import cn.medemede.springbootdemo1.exception.GirlException;
import cn.medemede.springbootdemo1.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GirlService {

    private final GirlRepository girlRepository;

    @Autowired
    public GirlService(GirlRepository girlRepository) {
        this.girlRepository = girlRepository;
    }

    public void getAge(Integer id) throws GirlException {
        Integer age = girlRepository.findOne(id).getAge();
        if (age < 10) {
            throw new GirlException(ResultEnum.PRIMARY_SCHOOL);
        } else {
            throw new GirlException(ResultEnum.HIGH_SCHOOL);
        }
    }
}
